package com.gopay.common.metric;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * 指标客户端
 * Created by xuHui on 2017/6/28.
 */
public class Client {
    private static final Logger logger = LoggerFactory.getLogger(Client.class);

    public static void record(Metric metric, String url) {
        String metricStr = JSON.toJSONString(metric, SerializerFeature.DisableCircularReferenceDetect);
        ResponseResult responseResult = HttpClient.post(url, metricStr);
        if (!responseResult.isSuccess()) {
            logger.info(metricStr);
        }
    }

    public static void record(List<Metric> metrics, String url) {
        String metricStr = JSON.toJSONString(metrics, SerializerFeature.DisableCircularReferenceDetect);
        ResponseResult responseResult = HttpClient.post(url, metricStr);
        if (!responseResult.isSuccess()) {
            logger.info(metricStr);
        }
    }
}
